package com.example.user.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.user.service.CoreDictService;
import entity.CoreDict;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.List;

/**
 * 字典表(CoreDict)表控制层
 *
 * @author makejava
 * @since 2022-03-31 15:58:43
 */
@RestController
@RequestMapping("coreDict")
@Slf4j
@Api(value="字典表接口",tags={"字典表接口的controller"})
public class CoreDictController  {
    /**
     * 服务对象
     */
    @Autowired
    private CoreDictService coreDictService;

    /**
     * 分页查询所有数据
     *
     * @param page     分页对象
     * @param coreDict 查询实体
     * @return 所有数据
     */
    @GetMapping
    public List<CoreDict> selectAll(Page<CoreDict> page, CoreDict coreDict) {
        return this.coreDictService.page(page, new QueryWrapper<>(coreDict)).getRecords();
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @ApiOperation(value="id查询字典",notes="id查询字典")
    public CoreDict selectOne(@PathVariable Serializable id) {
        String zhu ="222";
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        log.info(request.getRequestURL().toString());
        return this.coreDictService.getById(id);
    }

    /**
     * 新增数据
     *
     * @param coreDict 实体对象
     * @return 新增结果
     */
    @PostMapping
    public void insert(@RequestBody CoreDict coreDict) {
         this.coreDictService.save(coreDict);
    }

    /**
     * 修改数据
     *
     * @param coreDict 实体对象
     * @return 修改结果
     */
    @PutMapping
    public void update(@RequestBody CoreDict coreDict) {
         this.coreDictService.updateById(coreDict);
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public void delete(@RequestParam("idList") List<Long> idList) {
         this.coreDictService.removeByIds(idList);
    }
}

